package com.sctvcloud.bazhong.ui.adapter.holder;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.ruihang.generalibrary.ui.adapter.holder.BaseRecylerHolder;
import com.ruihang.generalibrary.ui.util.OnItemInternalClick;
import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.sctvcloud.bazhong.R;
import com.sctvcloud.bazhong.beans.FCityState;
import com.sctvcloud.bazhong.ui.utils.GlideCircleTransform;
import com.sctvcloud.bazhong.ui.utils.GlideUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/7/17 0017.
 */

public class CityStaChannelHolder extends BaseRecylerHolder<FCityState> implements View.OnClickListener {
    @BindView(R.id.item_city_state_channel_icon)
    protected CustomEXImageView icon;
    @BindView(R.id.item_city_state_channel_name)
    protected CustomFontTextView name;
    @BindView(R.id.item_city_state_channel_status)
    protected CustomFontTextView status;
    @BindView(R.id.item_city_state_channel_hot)
    protected ImageView hot_icon;
    private FCityState cityState;
    private OnItemInternalClick onItemInternalClick;

    public OnItemInternalClick getOnItemInternalClick() {
        return onItemInternalClick;
    }

    public void setOnItemInternalClick(OnItemInternalClick onItemInternalClick) {
        this.onItemInternalClick = onItemInternalClick;
    }

    public CityStaChannelHolder(Context context, View itemView) {
        super(context, itemView);
        itemView.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(FCityState state) {
        this.cityState = state;
        name.setText(state.getInstitutionName());
        GlideUtil.getGlid(context, state.getInstitutionImage()).error(R.mipmap.icon_circle_avatar)
                .placeholder(R.mipmap.icon_circle_avatar).transform(new GlideCircleTransform(context))
                .into(icon);
        status.setBackgroundResource(state.isSubscribe() ? R.drawable.ucrop_bg_cv_red : R.drawable.bg_look_back);
        status.setText(state.isSubscribe() ? context.getString(R.string.city_state_subscribe) : context.getString(R.string.city_state_no_subscribe));
        status.setTextColor(state.isSubscribe() ? context.getResources().getColor(R.color.white) : context.getResources().getColor(R.color.colorUpdate));
        if (state.getHotLevel().equals("0")) {
            hot_icon.setImageResource(R.mipmap.icon_hot_high);
        } else if (state.getHotLevel().equals("1")) {
            hot_icon.setImageResource(R.mipmap.icon_hot_mid);
        } else if (state.getHotLevel().equals("2")) {
            hot_icon.setImageResource(R.mipmap.icon_hot_low);
        }
    }

    @Override
    public void onClick(View v) {
        if (internalClick != null) {
            itemView.setTag(R.id.adapter_item_data_key, cityState);
            internalClick.onItemInternalClick(itemView, v, getAdapterPosition());
        }
    }

    @OnClick(value = {R.id.item_city_state_channel_status})
    public void subscribeClick(View view) {
        if (onItemInternalClick != null) {
            onItemInternalClick.onItemInternalClick(itemView, view, getAdapterPosition());
        }
    }
}
